home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / CLIPBOAR.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  287 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.4  $
  6. //
  7. // Definition of classes for clipboard Encapsulation
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_CLIPBOAR_H)
  10. #define OWL_CLIPBOAR_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15. #if !defined(OWL_EXCEPT_H)
  16. # include <owl/except.h>         // Owl exception classes
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. //
  28. // class TClipboard
  29. // ~~~~~ ~~~~~~~~~~
  30. // The clipboard class encapsulates the methods for the clipboard object
  31. // of Windows.
  32. //
  33. class _OWLCLASS TClipboard {
  34.   public:
  35.     // Constructors / destructor
  36.     //
  37.     TClipboard(HWND hWnd, bool mustOpen=true);  // aquire & open the clipboard
  38.    ~TClipboard();
  39.  
  40.     // Close & reopen the clipboard
  41.     //
  42.     void        CloseClipboard();
  43.     bool        OpenClipboard(HWND hWnd);
  44.  
  45.     operator    bool() const;
  46.  
  47.     HANDLE      GetClipboardData(uint format) const;
  48.     HWND        GetOpenClipboardWindow() const;
  49.     HWND        GetClipboardOwner() const;
  50.     HWND        GetClipboardViewer() const;
  51.     int         GetClipboardFormatName(uint format, char far* formatName,
  52.                                        int maxCount) const;
  53.     int         GetPriorityClipboardFormat(uint far* priorityList, int count) const;
  54.     int         CountClipboardFormats() const;
  55.     bool        IsClipboardFormatAvailable(uint format) const;
  56.     bool        EmptyClipboard();
  57.     uint        RegisterClipboardFormat(const char far* formatName) const;
  58.     HANDLE      SetClipboardData(uint format, HANDLE handle);
  59.     HWND        SetClipboardViewer(HWND hWnd) const;
  60.  
  61. #if defined(__OLE_H) || defined(_INC_OLE)
  62.     bool        QueryCreate(const char far* protocol = DefaultProtocol,
  63.                             OLEOPT_RENDER   renderopt= olerender_draw,
  64.                             OLECLIPFORMAT   format   = 0);
  65.     bool        QueryLink(const char far* protocol = DefaultProtocol,
  66.                           OLEOPT_RENDER   renderopt= olerender_draw,
  67.                           OLECLIPFORMAT   format   = 0);
  68. #endif
  69.  
  70. #if defined(OWL2_COMPAT)
  71.     // Obsolete way to retrieve the global clipboard object. The recomended
  72.     // way is to construct a TClipboard object using the TClipboard(HWND) ctor
  73.     //
  74.     static TClipboard& GetClipboard();
  75.     static TClipboard TheClipboard;
  76. #endif
  77.  
  78.     static const char* DefaultProtocol;
  79.  
  80.   protected_data:
  81.     bool              IsOpen;
  82.  
  83.     TClipboard();      // used by the obsolete global object
  84. };
  85.  
  86. //
  87. // class TXClipboard
  88. // ~~~~~ ~~~~~~~~~~~
  89. class _OWLCLASS_RTL TXClipboard : public TXOwl {
  90.   public:
  91.     TXClipboard(uint resourceId = IDS_CLIPBOARDBUSY);
  92. #if defined(BI_NO_COVAR_RET)
  93.     TXBase* Clone();
  94. #else
  95.     TXClipboard* Clone();
  96. #endif
  97.     void Throw();
  98.  
  99.     static void Raise(uint resourceId = IDS_CLIPBOARDBUSY);
  100. };
  101.  
  102. //
  103. // class TClipboardFormatIterator
  104. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
  105. class _OWLCLASS TClipboardFormatIterator {
  106.   public:
  107.     TClipboardFormatIterator(const TClipboard&);
  108.  
  109.     uint          Current();
  110.                   operator void* ();
  111.     uint          operator ++();
  112.     uint          operator ++(int);
  113.     void          Restart();
  114.  
  115.   private:
  116.     uint          _Current;
  117. };
  118.  
  119. // Generic definitions/compiler options (eg. alignment) following the 
  120. // definition of classes
  121. #include <services/posclass.h>
  122.  
  123. #if defined(BI_NAMESPACE)
  124. } // namespace OWL
  125. #endif
  126.  
  127. //----------------------------------------------------------------------------
  128. // Inline implementations
  129. //
  130.  
  131. #if defined(OWL2_COMPAT)
  132. //
  133. // Return the global clipboard object.
  134. //
  135. inline TClipboard& TClipboard::GetClipboard() {
  136.   return TheClipboard;
  137. }
  138. #endif
  139.  
  140. //
  141. // Create an empty clipboard object.
  142. // Set the state of the object to not opened.
  143. //
  144. inline TClipboard::TClipboard() {
  145.   IsOpen = false;
  146. }
  147.  
  148. //
  149. // Return true if the clipboard is currently owned by this application.
  150. //
  151. inline TClipboard::operator bool() const {
  152.   return IsOpen;
  153. }
  154.  
  155. //
  156. // Return the handle of the data that is on the clipboard.
  157. //
  158. inline HANDLE TClipboard::GetClipboardData(uint Format) const {
  159.   return ::GetClipboardData(Format);
  160. }
  161.  
  162. //
  163. // Return the HWND of the application that has the clipboard opened.
  164. //
  165. inline HWND TClipboard::GetOpenClipboardWindow() const {
  166.   return ::GetOpenClipboardWindow();
  167. }
  168.  
  169. //
  170. // Return the HWND of the application that owns the clipboard.
  171. //
  172. inline HWND TClipboard::GetClipboardOwner() const {
  173.   return ::GetClipboardOwner();
  174. }
  175.  
  176. //
  177. // Return the first HWND of the clipboard viewing chain.
  178. //
  179. inline HWND TClipboard::GetClipboardViewer() const {
  180.   return ::GetClipboardViewer();
  181. }
  182.  
  183. //
  184. // Retrieve the name of the format that is on the clipboard.
  185. //
  186. inline int TClipboard::GetClipboardFormatName(uint Format, char far* FormatName, int MaxCount) const {
  187.   return ::GetClipboardFormatName(Format, FormatName, MaxCount);
  188. }
  189.  
  190. //
  191. // Retrieve the name of the first format on the clipboard.
  192. //
  193. inline int TClipboard::GetPriorityClipboardFormat(uint far* priorityList, int count) const {
  194.   return ::GetPriorityClipboardFormat(priorityList, count);
  195. }
  196.  
  197. //
  198. // Return the number of formats available on the clipboard.
  199. //
  200. inline int TClipboard::CountClipboardFormats() const {
  201.   return ::CountClipboardFormats();
  202. }
  203.  
  204. //
  205. // Return true if the format is available.
  206. //
  207. inline bool TClipboard::IsClipboardFormatAvailable(uint format) const {
  208.   return ::IsClipboardFormatAvailable(format);
  209. }
  210.  
  211. //
  212. // Return true if the clipboard is empty.
  213. //
  214. inline bool TClipboard::EmptyClipboard() {
  215.   return ::EmptyClipboard();
  216. }
  217.  
  218. //
  219. // Register the name of a user-custom format.
  220. // The number returned is the custom format number that should be used with
  221. // SetClipboardData.
  222. //
  223. inline uint TClipboard::RegisterClipboardFormat(const char far* formatName) const {
  224.   return ::RegisterClipboardFormat(formatName);
  225. }
  226.  
  227. //
  228. // Copy the data onto the clipboard in the format.
  229. //
  230. inline HANDLE TClipboard::SetClipboardData(uint Format, HANDLE Handle) {
  231.   return ::SetClipboardData(Format,Handle);
  232. }
  233.  
  234. //
  235. // Add the HWND to the clipboard viewer chain.
  236. //
  237. inline HWND TClipboard::SetClipboardViewer(HWND Wnd) const {
  238.   return ::SetClipboardViewer(Wnd);
  239. }
  240.  
  241. #if defined(__OLE_H) || defined(_INC_OLE)
  242. //
  243. // Return true if the object on the clipboard can be rendered in the
  244. // requested format.
  245. //
  246. inline bool TClipboard::QueryCreate(
  247.                 const char far* protocol,
  248.                 OLEOPT_RENDER   renderopt,
  249.                 OLECLIPFORMAT   format
  250.               )
  251. {
  252.   return ::OleQueryCreateFromClip(protocol, renderopt, format) == OLE_OK;
  253. }
  254.  
  255. //
  256. // Return true if the object on the clipboard can be linked to in the
  257. // requested format.
  258. //
  259. inline bool TClipboard::QueryLink(
  260.                 const char far* protocol,
  261.                 OLEOPT_RENDER   renderopt,
  262.                 OLECLIPFORMAT   format
  263.               )
  264. {
  265.   return ::OleQueryLinkFromClip(protocol, renderopt, format) == OLE_OK;
  266. }
  267. #endif
  268.  
  269.  
  270. //
  271. // Return the current clipboard format.
  272. //
  273. inline uint TClipboardFormatIterator::Current() {
  274.   return _Current;
  275. }
  276.  
  277. //
  278. // Return true if the iterator is not at an end of the clipboard format
  279. // chain.
  280. //
  281. inline TClipboardFormatIterator::operator void* () {
  282.   return _Current ? this : 0;
  283. }
  284.  
  285.  
  286. #endif  // OWL_CLIPBOAR_H
  287.